<?php
class HTMLHelper {

  public static function baseTag($base = null, $return = false){

    if(is_null($base)) $base = self::baseUrl(true);

    $tag = '<base href="'.$base.'" />';

    if(!$return){
      echo $tag;
    } else {
      return $tag;
    }
   
  }

  public static function removeLeadingSlash($string){
    if(substr($string, 0, 1) == '/') $string = substr($string, 1);

    return $string;
  }
  
  public static function baseUrl($return = false){
    $base_url = Config::get('base_url', '/');
    if($return){
        return $base_url;
    } else {
        echo $base_url;
    }
  }
  
  public static function absoluteRoot($return = false){
    $base_url = Config::get('absolute_url', 'http://'.$_SERVER['HTTP_HOST'].'/');
    if($return){
        return $base_url;
    } else {
        echo $base_url;
    }
  }

  public static function addHttp($string){
    if(substr($string, 0, 7) != 'http://' && substr($string, 0, 8) != 'https://') $string = 'http://'.$string;
    return $string;
  }

  public static function addHttps($string){
    if(substr($string, 0, 7) != 'http://' && substr($string, 0, 8) != 'https://') $string = 'https://'.$string;
    return $string;
  }

  public static function removeHttp($string){
    if(substr($string, 0, 7) == 'http://') $string = substr($string, 7);
    return $string;
  }

}